@extends('admin.layouts.index')
@section('title', '发票申请记录')

@section('content')
<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-body">
                <form class="m-search" method="GET" action="{{ URL::current() }}">
                    <div class="m-search-items">
                        <div class="m-search-item">
                            <label>公司名称</label>
                            <input type="text" name="title" placeholder="请输入公司名称">
                        </div>
                        <div class="m-search-item">
                            <button class="button">搜索</button>
                        </div>
                    </div>
                    <div class="m-search-handle">
                        <a class="button" href="{{ url('/admin/users/member_orders_invoice') }}">
                            <i class="iconfont icon-jiahao"></i>
                            <font>申请开增值税发票</font>
                        </a>
                    </div>
                </form>
                <div class="self-table-responsive">
                    <table class="table table-bordered table-nowrap">
                        <thead>
                            <tr>
                                <th scope="col">发票抬头</th>
                                <th scope="col">用户昵称</th>
                                <th scope="col">公司税号</th>
                                <th scope="col">发票接收邮箱</th>
                                <th scope="col">金额</th>
                                <th scope="col">状态</th>
                                <th scope="col">开票时间</th>
                                <th scope="col">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($invoices as $invoice)
                            <tr>
                                <td>{{ $invoice->company_name }}</td>
                                <td><a href="{{ url('/admin/users/users_detial',['users_id'=>$invoice->users_id]) }}">{{ $invoice->nike }}</a></td>
                                <td>{{ $invoice->company_tax_number }}</td>
                                <td>{{ $invoice->email }}</td>
                                <td>¥{{ $invoice->price }}</td>
                                @if($invoice->status == 1)
                                <td class="text-default">未开票</td>
                                @else
                                <td class="text-success">已开票</td>
                                @endif
                                <td>{{ $invoice->created_at  }}</td>
                                <td>
                                    @if(Auth::user()->authority == 3)
                                    <font class="text-primary" onclick="updateInvoiceStatus('{{ $invoice->id }}','{{ $invoice->company_name }}');">上传发票</font>@if(!empty($invoice->images)) | @endif
                                    @endif
                                    @if(!empty($invoice->images))
                                    <font class="text-primary" onclick="showInvoice('{{ $invoice->images }}')">查看发票</font>
                                    @endif
                                </td>
                            </tr>
                            @empty
                            <tr>
                                <td colspan="8">当前暂无开票记录</td>
                            </tr>
                            @endforelse
                        </tbody>
                    </table>
                    <div class="pagination-container">
                        {!! $invoices->appends($condition)->render() !!}
                    </div>
                </div>
                <div class="phone-table-alert"></div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="POST" action="{{ url('/admin/users/users_invoice_detial') }}" enctype="multipart/form-data">
                <div class="modal-header">
                    <h6 class="modal-title">更新发票信息</h6>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    @csrf
                    <input type="hidden" name="id" id="mid">
                    <input type="file" accept="image/*" name="images" class="form-control mg-b-sm" value="">
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary" id="creatuserbutton">立即发布</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="imageModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
                <div class="modal-header">
                    <h6 class="modal-title">查看发票</h6>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body" style="text-align: center;">
                   <img src="" id="invoiceImage" style="width: 100%;">
                </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    function updateInvoiceStatus(id,company_name) {
        $("#mid").val(id);
        $('#myModal').modal('toggle');
    }

    function showInvoice(images) {
        $("#invoiceImage").attr("src",images);
        $('#imageModal').modal('toggle');
    }
</script>

@endsection
